package com.xdf.whiteaccount.controller;

import com.xdf.whiteaccount.entity.ContactCompany;
import com.xdf.whiteaccount.entity.ResponseResult;
import com.xdf.whiteaccount.enums.MenuConstant;
import com.xdf.whiteaccount.enums.OperateConstant;
import com.xdf.whiteaccount.enums.ResponseEnum;
import com.xdf.whiteaccount.enums.SeparatorConstant;
import com.xdf.whiteaccount.utils.Example;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.xdf.whiteaccount.entity.Defectivegoods;
import com.xdf.whiteaccount.service.DefectivegoodsService;
import com.xdf.whiteaccount.utils.JsonResult;

/**
 * 版本号：20240401
 * 注意要有依赖：
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger2</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger-ui</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 * 同时入口类头上使用注解：@EnableSwagger2
 * @Description : 控制层，自定义代码写在最后
 * @Author : chanchaw
 * @Date : 2025-9-5 14:54:28
 */
@Api(tags = "待处理原因")
@CrossOrigin
@RestController
@RequestMapping("/defectivegoods")
public class DefectivegoodsController {
    @Autowired
    private DefectivegoodsService service;

    // 全部属性新增
    @ApiOperation(value = "完全新增", httpMethod = "POST", notes = "推荐使用save请求")
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody Defectivegoods record){
        return JsonResult.ok(service.insert(record));
    }

    // 选择属性新增。value=null 的属性不会写入DB，DB会填充默认值
    @ApiOperation(value = "选择新增", httpMethod = "POST", notes = "自动生成的新增方法")
    @RequiresPermissions(MenuConstant.MENU421 + SeparatorConstant.SEPARATOR + OperateConstant.ADD)
    @RequestMapping(value = "/insertSelective", method = RequestMethod.POST)
    public ResponseResult<Void> insertSelective(Defectivegoods record) throws Exception {
        service.insertSelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    // 根据主键删除，切记表要有主键，否则为删除所有数据！！！！！！！！！！
    @ApiOperation(value = "根据主键删除方法", httpMethod = "DELETE", notes = "自动生成的删除方法")
    @RequiresPermissions(MenuConstant.MENU421 + SeparatorConstant.SEPARATOR + OperateConstant.DELETE)
    @RequestMapping(value = "/deleteByPk", method = RequestMethod.POST)
    public ResponseResult<Void> deleteByPrimaryKey(@RequestParam("bitemId") Object bitemId) throws Exception {
        service.deleteByPrimaryKey(Integer.valueOf(bitemId.toString()));
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    // 根据主键查询，切记表要有主键，否则为查询所有数据！！！！！！！！！！
    @ApiOperation(value = "根据主键查询", httpMethod = "GET", notes = "自动生成的查询方法")
    @RequestMapping(value = "/queryByPk/{id}", method = RequestMethod.GET)
    public Defectivegoods selectByPrimaryKey(@PathVariable("id") Integer id) throws Exception {
        if (id == null) return null;
        return service.selectByPrimaryKey(id);
    }

    // 获取所有数据
    @ApiOperation(value = "查询所有", httpMethod = "POST", notes = "所有请求都是post")
    @PostMapping("/selectAll")
    public JsonResult selectAll(){
        return JsonResult.ok(service.selectAll());
    }

    // 全部属性更新。前端传递来属性value=null则会设置后台数据为null
    @ApiOperation(value = "完全修改", httpMethod = "POST", notes = "推荐使用save方法")
    @PostMapping("/updateByPrimaryKey")
    public JsonResult updateByPrimaryKey(@RequestBody Defectivegoods record) {
        return JsonResult.ok(service.updateByPrimaryKey(record));
    }

    // 部分属性更新。前端传递来value=null的属性不会被更新到数据库
    @ApiOperation(value = "选择修改", httpMethod = "PUT", notes = "自动生成的修改方法")
    @RequiresPermissions(MenuConstant.MENU421 + SeparatorConstant.SEPARATOR + OperateConstant.MODIFY)
    @RequestMapping(value = "/updateSelective", method = RequestMethod.POST)
    public ResponseResult<Void> updateSelective(Defectivegoods record) throws Exception {
        service.updateByPrimaryKeySelective(record);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    // 有则修改，无则新增。选择性保存，如果属性value=null则不会更新该字段
    @ApiOperation(value = "保存数据", httpMethod = "POST", notes = "主键为空则新增(选择性新增)，主键有值则修改（选择性修改）")
    @PostMapping("/save")
    public JsonResult save(@RequestBody Defectivegoods record) {
        return JsonResult.ok(service.save(record));
    }

    // 是上面接口 save 的批量执行版本
    @ApiOperation(value = "批量新增", httpMethod = "POST", notes = "自动生成的新增方法")
    @RequiresPermissions(MenuConstant.MENU421 + SeparatorConstant.SEPARATOR + OperateConstant.MODIFY)
    @RequestMapping(value = "/multiInsert", method = RequestMethod.POST)
    public ResponseResult<Void> multiInsert(@RequestBody List<Defectivegoods> list) throws Exception {
        service.multiInsert(list);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }

    @ApiOperation(value = "查询方法", httpMethod = "GET", notes = "自动生成的查询方法")
    @RequestMapping(value = "/listQuery", method = RequestMethod.GET)
    public List<Defectivegoods> query(Defectivegoods record) throws Exception {
        List<Defectivegoods> ret = service.selectByParam(record);
        return ret;
    }
}